import type { OptionsRow, PlusColumn } from 'plus-pro-components'

import { getProjectList } from '@fl/api/order/base'
import { useStoreDict } from '@fl/store/modules/goodHouseDict'

const dictStore = useStoreDict()
dictStore.init(['order_ddzt'])
const { getDicts } = storeToRefs(dictStore)

const projectList: Ref<OptionsRow[]> = ref([])
const searchLoading = ref(false)
async function getList() {
    searchLoading.value = true
    await getProjectList().then((res) => {
        // projectList.value = [{label: '全部', value:'all'}]
        projectList.value = (res?.data || []).map((r) => {
            return { label: r.xsmc, value: r.id }
        })
    })
    searchLoading.value = false
}
getList()

export function useForm() {
    const schema: PlusColumn[] = [
        {
            colProps: {
                span: 6,
            },
            label: '订单编号',
            prop: 'orderNumber',
            valueType: 'copy',
        },
        {
            colProps: {
                span: 6,
            },
            label: '客户名称',
            prop: 'userName',
            valueType: 'copy',
        },
        {
            colProps: {
                span: 6,
            },
            fieldProps: {
                endPlaceholder: '结束日期',
                format: 'YYYY-MM-DD HH:mm:ss',
                startPlaceholder: '开始日期',
                type: 'datetimerange',
                valueFormat: 'YYYY-MM-DD HH:mm:ss',
            },
            label: '提交时间',
            prop: 'createTime',
            valueType: 'date-picker',
        },
        {
            colProps: {
                span: 6,
            },
            fieldProps: {
                filterable: true,
            },
            label: '订单状态',
            options: computed(() => getDicts.value.order_ddzt),
            prop: 'status',
            valueType: 'select',
        },
        {
            colProps: {
                span: 6,
            },
            fieldProps: {
                filterable: true,
                // loading: searchLoading.value,
                // remote: true,
                // multiple: true,
                // remoteMethod,
                // remoteShowSuffix: true,
            },
            label: '所属项目',
            options: computed(() => projectList.value),
            prop: 'projectBaseId',
            valueType: 'select',
        },
        {
            colProps: {
                span: 6,
            },
            fieldProps: {
                endPlaceholder: '结束日期',
                format: 'YYYY-MM-DD HH:mm:ss',
                startPlaceholder: '开始日期',
                type: 'datetimerange',
                valueFormat: 'YYYY-MM-DD HH:mm:ss',
            },
            label: '取消时间',
            prop: 'cancelTime',
            valueType: 'date-picker',
        },
    ]

    const state = {
        cancelTime: '',
        createTime: '',
        orderNumber: '',
        projectBaseId: null,
        status: '',
        userName: '',
    }
    const form = ref({
        ...state,
    })
    return { form, schema, state }
}
